package org.mpremote.android.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import org.mpremote.android.R;
import org.mpremote.android.activities.abstracts.MPActivity;
import org.mpremote.android.framework.database.MPDataManager;

/**
 * Created by IntelliJ IDEA.
 * User: Gilad
 * Date: 27/08/2010
 * Time: 19:20:34
 */
public class HomeActivity extends MPActivity {

    MPDataManager mpDataManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        initConfigurationButton();
        initMusicLibraryButton();
        mpDataManager = new MPDataManager(getApplicationContext());
    }

    private void initConfigurationButton() {
        final Button configurationButton = ((Button) findViewById(R.id.configuration_button));
        configurationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(HomeActivity.this, ConfigurationActivity.class));
            }
        });
    }

    private void initMusicLibraryButton() {
        final Button configurationButton = ((Button) findViewById(R.id.music_button));
        configurationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(HomeActivity.this, MusicLibraryActivity.class));
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.home_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        final int itemId = item.getItemId();
        if (itemId == R.id.drop_database) {
            mpDataManager.recreateDatabase();
        }
        return super.onOptionsItemSelected(item);
    }
}
